This section describes the functions that move windows on the desktop.
To move a window, your application ordinarily needs to call only the DragWindow function (DragWindow) , which itself calls the DragGrayRgn function (DragGrayRgn) , and the MoveWindow function (MoveWindow) . The DragGrayRgn function drags a dotted outline of the window on the screen, following the motion of the cursor, as long as the user holds down the mouse button. The DragGrayRgn function itself calls the PinRect function (PinRect) to contain the point where the cursor was when the mouse button was first pressed inside the available desktop area. When the user releases the mouse button, DragWindow calls MoveWindow , which moves the window to a new location.
Moves a window on the screen when the user drags it by its title bar.
pascal void DragWindow (WindowPtr theWindow,
Point startPt,
const Rect *boundsRect);
The DragWindow function uses DragGrayRgn (DragGrayRgn) to move a dotted outline of the specified window around the screen, following the movement of the cursor until the user releases the mouse button. When the button is released, DragWindow calls MoveWindow (MoveWindow) to move the window to its new location. If the specified window isn't the active window (and the Command key wasn't down when the mouse button was pressed), DragWindow makes it the active window by setting the front parameter to true when calling MoveWindow . If the Command key was down when the mouse button was pressed, DragWindow moves the window without making it active.
Moves a window on the desktop.
pascal void MoveWindow (WindowPtr theWindow,
short hGlobal,
short vGlobal,
Boolean front);
The MoveWindow function moves the specified window to the location specified by the hGlobal and vGlobal parameters, without changing the window's size. The upper-left corner of the window's port rectangle is placed at the point ( vGlobal , hGlobal ). The local coordinates of the upper-left corner are unaffected.
Your application doesn't normally call MoveWindow . When the user drags a window by dragging its title bar, you can call DragWindow (DragWindow) which in turn calls MoveWindow when the user releases the mouse button.
The DragWindow function (DragWindow) calls the DragGrayRgn function to move an outline of a window around the screen as the user drags a window.
pascal long DragGrayRgn (RgnHandle theRgn,
Point startPt,
const Rect *limitRect,
const Rect *slopRect,
short axis,
DragGrayRgnProcUPP actionProc);
enum {
noConstraint = 0, /* no constraints */
hAxisOnly = 1, /* move on horizontal axis
/* only */
vAxisOnly = 2 /* move on vertical axis */
/* only */
};
The DragGrayRgn function moves a gray outline of a region on the screen, following the movements of the cursor, until the mouse button is released. It returns the difference between the point where the mouse button was pressed and the offset point --that is, the point in the region whose horizontal and vertical offsets from the upper-left corner of the region's enclosing rectangle are the same as the offsets of the starting point when the user pressed the mouse button. The DragGrayRgn function stores the vertical difference between the starting point and the offset point in the high-order word of the return value and the horizontal difference in the low-order word.
The DragGrayRgn function limits the movement of the region according to the constraints set by the limitRect and slopRect parameters:
Figure 3-1 illustrates how the region stops moving when the offset point reaches the edge of the limitRect rectangle. The cursor continues to move, but the region does not.
If the mouse button is released while the cursor is anywhere inside the slopRect rectangle, the Window Manager redraws the window in its new location, which is calculated from the value returned by DragGrayRgn .
Figure 1 Limiting rectangle used by DragGrayRgn
You can set the global variable DragHook to point to an optional function, defined by your application, which will be called by DragGrayRgn as long as the mouse button is held down. (If there's an actionProc function, it is called first.) If you want DragGrayRgn to draw the region's outline in a pattern other than gray, you can store the pattern in the global variable DragPattern and then invoke the macro _DragTheRgn . Note that the use of the Window Manager's global variables is not guaranteed to be compatible with system software versions later than System 6.
The DragGrayRgn function uses the PinRect function to contain a point within a specified rectangle.
pascal long PinRect (const Rect *theRect, Point *thePt);
The PinRect function returns a point within the specified rectangle that is as close as possible to the specified point. (The high-order word of the returned long integer is the vertical coordinate; the low-order word is the horizontal coordinate.)
If the specified point is within the rectangle, PinRect returns the point itself. If not, then
The 1 is subtracted when the point is below or to the right of the rectangle so that a pixel drawn at that point lies within the rectangle. If the point is exactly on the bottom or the right edge of the rectangle, however, 1 should be subtracted but isn't.